﻿using System.Collections.Generic;
using System.Linq;

namespace Project5188.BUS.EducationAndTraining
{
    public class Courses : DetailView<course>
    {
        private project5188Entities _context;
        // ReSharper disable InconsistentNaming
        private new List<course> EntityList;
        private new course Entity;
        // ReSharper restore InconsistentNaming

        public long TransactionId { get; private set; }

        #region Overrides of DetailView<course>

        public override List<course> GetEntityList()
        {
            _context = new project5188Entities();
            EntityList = _context.courses.Where(a => !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override List<course> GetEntityById(long id)
        {
            _context = new project5188Entities();
            EntityList = _context.courses.Where(a => a.a_ID == id && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override course GetEntity()
        {
            _context = new project5188Entities();
            Entity = new course();
            return Entity;
        }

        public override void Update()
        {
            _context.SaveChanges();
        }

        public override void Insert()
        {
            _context.AddTocourses(Entity);
            _context.SaveChanges();
            TransactionId = Entity.a_ID;
        }

        #endregion

        public List<course> GetEntityListByParameters(string courseName)
        {
            _context = new project5188Entities();

            EntityList = _context.courses.Where(a => (a.c_CourseName.Contains(courseName)) && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }
    }
}
